package Monopol.AssetGroups;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Iterator;

import Player.Player;
import Square.City;

/**
 * @author Avia Tam
 * @author Assaf Miron
 * 
 */
public class State implements AssetGroup{
 private String name; // State Name
 private ArrayList<City>cities; // All the State Cities
 private Boolean isHouseExists; // Indicates if there is a House in one of the Cities in this State
 private Color stateColor;
 
	/**
	 * Constructs the State with Empty City List
	 * @param name The State Name
	 */
	public State(String name, Color color) {
		this.name = name; // Initialize the State Name
		this.cities = new ArrayList<City>(); // Allocate new Cities Array List
		this.cities.clear(); // Initialize the Cities List
		this.isHouseExists = false; // Set that there are no Houses in this State
		this.stateColor = color; // Set the State Color
	}

	/**
	 * Adds a New City o the State
	 * @param squares The City Object
	 */
	public void addCity(City squares  ) {
		this.cities.add(squares) ;
	}
	
	/**
	 * @return The Name of the State
	 */
	public String getName() {
		return name;
	}
	
	/**
	 * @return An Array List of Cities in the State
	 */
	public ArrayList<City> getCities() {
		return cities;
	}

	
	/**
	 * This Function Create a City From the properties inputed, 
	 * and adds it to the Cities Array in the State
	 * @param cityName The City Name
	 * @param stayPrice The City Stay Price Array (With 1 House, With 2 Houses, With 3 Houses)
	 * @param cost The City Buy Cost
	 * @param housePrice The House Cost for Each House in the City
	 * @return The New Created City
	 */
	public City CreateCity(String cityName, Double[] stayPrice, Double cost, Double housePrice ) {
		// Create the New City
		City city = new City(cityName, stayPrice, cost, housePrice,this);
		// Add the City to the List of Cities
		this.addCity(city);
		// Return the New City Object
		return city;
	}

	/* (non-Javadoc)
	 * @see Monopol.AssetGroup#isAllAssetGroupMine(Player.Player)
	 */
	@Override
	public Boolean isAllAssetGroupMine(Player player){
		// Create an Iterator to run on the Assets Group
		Iterator<City> i = cities.iterator();		 
		// Create a Temporary boolean variable - Check if all the group is owned by the same Player
		Boolean allGroups = new Boolean(true);
		// Loop the State while all the Cities have the same Owner
		while(i.hasNext() && allGroups)
		{
			// Check the Owner and compare with the Player
			if(i.next().getOwner() != player)
			{
				// Not the Same Owner as Player - Stop Checking
				allGroups = false;
			}
		}
		// Return the Value of All Groups
		return allGroups;
	}

	/**
	 * @param isHouseExists the isHouseExists to set
	 */
	public void setIsHouseExists(Boolean isHouseExists) {
		this.isHouseExists = isHouseExists;
	}

	/**
	 * @return the isHouseExists
	 */
	public Boolean getIsHouseExists() {
		return isHouseExists;
	}

	/* (non-Javadoc)
	 * @see Monopol.AssetGroup#getAssets()
	 */
	@Override
	public ArrayList<?> getAssets() {
		return cities;
	}

	/* (non-Javadoc)
	 * @see Monopol.AssetGroups.AssetGroup#getColor()
	 */
	@Override
	public Color getColor() {
		return stateColor;
	}
	
}
